﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core.Interfaces;

namespace Cofe.Core
{
    public static class IVolumeRegistrarExtension
    {
        public static bool IsSystemFactory(this IVolumeRegistrar volumeRegistrar, string factoryId)
        {
            var ft = volumeRegistrar.VolumeFactories.FirstOrDefault(f => f.FactoryId == factoryId);
            if (ft == null)
                throw new KeyNotFoundException(factoryId);
            return ft is ISystemVolumeFactory;
        }

        public static bool IsSystemVolume(this IVolumeRegistrar volumeRegistrar, string volumeId)
        {
            var vol = volumeRegistrar.LookupVolume(volumeId);           
            if (vol == null)
                throw new KeyNotFoundException(volumeId);
            return volumeRegistrar.IsSystemFactory(vol.FactoryId);
        }
    }
}
